package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Vehicle;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VehicleMapper extends BaseMapper<Vehicle> {

    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "parking_lot_id",property = "parkingLot",one =@One(select = "com.example.demo.mapper.ParkingLotMapper.getById"))
    })
    @Select("select * from vehicle join parking_lot " +
            "on parking_lot.id=parking_lot_id")
    List<Vehicle> getAll();

    @Select("select * from vehicle join parking_lot " +
            "on parking_lot_id=parking_lot.id" +
            " where vehicle.id=#{id}")
    Vehicle getById(Long id);

    @Insert("insert into vehicle set licence_plate=#{licencePlate}" +
            " ,piUrl=#{piUrl}" +
            ",parking_lot_id=#{parkingLot.id}" +
            ",is_active=#{isActive}")
    int insert(Vehicle entity);

    @Update("update vehicle set licence_plate=#{licencePlate}" +
            ",piUrl=#{piUrl}" +
            ",parking_lot_id=#{parkingLot.id}" +
            ",is_active=#{isActive}" +
            " where id=#{id}")
    int update(Vehicle entity);

}
